import analysis.AnalysisMain;
import http.HttpGroup;
import model.ApiConfigDataModel;
import model.ApiDataModel;
import readWirteExcel.ApiGroup;
import readWirteExcel.CreateSqlConnection;
import saveData.CreateDir;
import saveData.Save2txt;

import java.util.ArrayList;

/**
 * Created by yangxianming on 2015-06-08.
 之所以在读取数据的时候创建数据库连接,是因为可以在每个测试用例文件中配置数据库连接
 这样就必须在读取文件的过程中创建数据库连接.
 之后会支持xml测试数据的读取 或者是json形式也同样可以是这样的做法
 先操作getConfigData的配置数据后可以替换测试数据中的引用值
 */
public class Main {
    public static void main(String[] args) {
        String projectDir = "";
        if (args[0].substring(0, 4).equals("dir|")){
            projectDir = args[0].substring(4);
            args[0] = "";
        }
//        CreateDir createDir = new CreateDir();
        String resultFilePath = CreateDir.createDirPart();
//        for (int i=0; i<2; i++){
            for (String fileName:args){
                if (fileName == "")
                    continue;
//              String fileName = "ws2.xls";
//              String fileName = args[0];

//        获取数据,创建数据库连接
                ApiGroup apiGroup = new ApiGroup(projectDir, fileName);
                ApiConfigDataModel acdm = apiGroup.getConfigData();
                CreateSqlConnection csc = new CreateSqlConnection(acdm);
                csc.createConnection();
                ArrayList<ApiDataModel> list = apiGroup.getApiList(acdm);

//        http操作
                HttpGroup httpGroup = new HttpGroup(list, acdm);
                httpGroup.http();

//        分析结果
                AnalysisMain analysisMain = new AnalysisMain(list, acdm);
                analysisMain.parse();

//        记录结果到媒介上
                Save2txt save2txt = new Save2txt(fileName, resultFilePath);
                save2txt.save(list);

                System.out.println();
            }
//        }
    }
}
